<?php
namespace Admin\Controller;

class UseronlineController extends AdminController
{
	public function index()
	{
		$Part = A('Part');
		$partlist = $Part->viewlist();
		$this->assign('partlist', $partlist);
		$Project = A('Project');
		$Projectlist = $Project->viewWidgetIndex();
		$this->assign('projectlist', $Projectlist);
		$this->display();
	}
	public function view()
	{
		//Load('extend');



		$n = D("User");
		import("ORG.Util.Page"); //导入分页类
		$page = $_POST["page"];
		$rows = $_POST["rows"];
		$sort = $_POST["sort"] ? $_POST["sort"] : 'id';
		$order = $_POST["order"] ? $_POST["order"] : 'desc';
		if ($sort == 'part') {
			$sort = 'partid';
		}
		$condition['update_time'] = array("egt", date("Y-m-d H:i:s", time() - (31 * 60)));
		//dump($order);
		if ($_POST["account"] != null && $_POST["account"] != "") {
			$condition['account'] = array('like', '%' . $_POST["account"] . '%');
		}
		if (I("partid") != null && I("partid") != "") {
			$condition['partid'] = I("partid");
		}
		if (I("projectid") != null && I("projectid") != "") {
			$condition_project_user['project_id'] = I("projectid");
			$useridarray = M('project_user')->where($condition_project_user)->getField('user_id', true);
			$condition['id'] = array('in', $useridarray);
		}
		if ($_POST["createdatetimeStart"] != null && $_POST["createdatetimeStart"] != "") {
			$condition['create_time'] = array('between', $_POST["createdatetimeStart"], $_POST["createdatetimeEnd"]);
		}
		if ($_POST["modifydatetimeStart"] != null && $_POST["modifydatetimeStart"] != "") {
			$condition['update_time'] = array('between', $_POST["modifydatetimeStart"], $_POST["modifydatetimeEnd"]);
		}
		$count = $n->where($condition)->count(); //计算总数
		//$p = new Page($count,$rows);order($sort+','+$order)->	
		$list = $n->relation(true)->where($condition)->field('bind_p,password', true)->page($page, $rows)->order(array($sort => $order))->select();
		foreach ($list as $key => $value) {
			$list[$key]['partpid'] = $value['part']['pid'];
		}
		//dump($n->getLastSql());
		$list = json_encode($list);
		$result = '{"total":' . $count . ',"rows":' . $list . '}';
		echo ($result); //输出json数据 
	}
}
